package top.shen33.yang.base.config;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.shen33.yang.base.eventListener.EventListener;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.PostConstruct;

@Configuration
public class EventBusConfig {

    @Autowired
    private List<EventListener> eventListenerList;

    @Bean
//    @Bean(name = "eventBus",initMethod = "init")
    public EventBus eventBus(){
        return new EventBus();
    }

    @PostConstruct
    public void init(){
        EventBus eventBus = this.eventBus();
        for (EventListener listener : eventListenerList) {
            eventBus.register(listener);
        }
    }

//    @Bean
//    public AsyncEventBus asyncEventBus(){
//
//        ExecutorService pool = Executors.newFixedThreadPool(10);
//        return new AsyncEventBus("asyncEventBus",pool);
//    }


}
